<template>
	<view class="save-incons"  @click.stop="_changSaveStatus">
		<uni-icons color="#ff6600" :type="status?'heart-filled':'heart'" :size="size"></uni-icons>
	</view>
</template>

<script>
	export default {
		name:"SaveLikes",
		props:{
			item:{
				type:Object // 单项文章数据
			},
			size:{
				type:String,
				default:'20'
			}
		},
		data() {
			return {
			};
		},
		methods: {
			async _changSaveStatus() {
				// TODOS 判断用户是否登录
				await this.checkedisLogin();
				const { msg, newUserInfo } = await this.$http.updateSaveLike({
					articleId: this.item._id,
					userId: this.userInfo._id
					})
				uni.showToast({
					title: msg,
					icon: 'none'
				})
				// 发送事件监听
				// 触发followarticle界面从新进行列表数据获取
				uni.$emit('updateArticle')
				// 合并新旧用户信息
				this.updateUserInfo({ ...this.userInfo, ...newUserInfo })
			}
		},
		computed: {
			status () {
				// 收藏的状态显示
				return this.userInfo && this.userInfo.article_likes_ids.includes(this.item._id)
			}
		}
	}
</script>

<style>

</style>
